﻿using System;
using Fabrication.DataSources;

namespace Fabrication.ValueProviders
{
    internal class LoremIpsumProvider : ValueProviderBase<string>
    {
        private static readonly int standardLength = 448;
        private static readonly int maxLength = LoremIpsum.Text.Length;
        private readonly int length;

        public LoremIpsumProvider(int? length = null)
        {
            var requestedLength = length.HasValue ? Math.Max(1, length.Value) : standardLength;
            this.length = Math.Min(requestedLength, maxLength);
        }

        protected override string GetValue(object item)
        {
            return LoremIpsum.Text.Substring(0, length);
        }
    }
}